package com.ruoyi.web.controller.food;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.entity.Result;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GrainsituationRecord;
import com.ruoyi.system.service.IGrainsituationRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 粮情主Controller
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/web/record")
@Api(tags = "粮情主")
public class GrainsituationRecordController extends BaseController<GrainsituationRecord>
{
    @Autowired
    private IGrainsituationRecordService grainsituationRecordService;

    /**
     * 查询粮情主列表-分页
     */
    @ApiOperation(value = "查询粮情主列表-分页")
    @PreAuthorize("@ss.hasPermi('web:record:page')")
    @GetMapping("/page")
    public Result<List<GrainsituationRecord>> page(GrainsituationRecord grainsituationRecord)
    {
        startPage();
        List<GrainsituationRecord> list = grainsituationRecordService.selectGrainsituationRecordList(grainsituationRecord);
        return getPageTable(list);
    }

    /**
     * 查询粮情主列表
     */
    @ApiOperation(value = "查询粮情主列表")
    @PreAuthorize("@ss.hasPermi('web:record:list')")
    @GetMapping("/list")
    public Result<List<GrainsituationRecord>> list(GrainsituationRecord grainsituationRecord)
    {
        List<GrainsituationRecord> list = grainsituationRecordService.selectGrainsituationRecordList(grainsituationRecord);
        return Result.ok(list);
    }

    /**
     * 导出粮情主列表
     */
    @ApiOperation(value = "导出粮情主列表")
    @PreAuthorize("@ss.hasPermi('web:record:export')")
    @Log(title = "粮情主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrainsituationRecord grainsituationRecord)
    {
        List<GrainsituationRecord> list = grainsituationRecordService.selectGrainsituationRecordList(grainsituationRecord);
        ExcelUtil<GrainsituationRecord> util = new ExcelUtil<GrainsituationRecord>(GrainsituationRecord.class);
        util.exportExcel(response, list, "粮情主数据");
    }

    /**
     * 获取粮情主详细信息
     */
    @ApiOperation(value = "获取粮情主详细信息")
    @PreAuthorize("@ss.hasPermi('web:record:query')")
    @GetMapping(value = "/{id}")
    public Result<GrainsituationRecord> getInfo(@PathVariable("id") Long id)
    {
        return Result.ok(grainsituationRecordService.selectGrainsituationRecordById(id));
    }

    /**
     * 新增粮情主
     */
    @ApiOperation(value = "新增粮情主")
    @PreAuthorize("@ss.hasPermi('web:record:add')")
    @Log(title = "粮情主", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody GrainsituationRecord grainsituationRecord)
    {
        return Result.ok(grainsituationRecordService.insertGrainsituationRecord(grainsituationRecord));
    }

    /**
     * 修改粮情主
     */
    @ApiOperation(value = "修改粮情主")
    @PreAuthorize("@ss.hasPermi('web:record:edit')")
    @Log(title = "粮情主", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody GrainsituationRecord grainsituationRecord)
    {
        return Result.ok(grainsituationRecordService.updateGrainsituationRecord(grainsituationRecord));
    }

    /**
     * 删除粮情主
     */
    @ApiOperation(value = "删除粮情主")
    @PreAuthorize("@ss.hasPermi('web:record:remove')")
    @Log(title = "粮情主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return Result.ok(grainsituationRecordService.deleteGrainsituationRecordByIds(ids));
    }
}
